/** @type {HTMLCanvasElement} */
console.log(mapInfo);
const c2 = document.getElementById("c2");
const ctx2 = c2.getContext("2d");
let i = -1;
// 设置canvas宽高函数
setCanvasWH(c2, ctx2, window.innerWidth, window.innerHeight);
// console.log(polygonVertices);
// 监听鼠标移动事件
c2.addEventListener("mousemove", function (event) {
  // 获取鼠标在 Canvas 上的坐标位置
  const mouseX = event.offsetX;
  const mouseY = event.offsetY;
  // 判断鼠标位置是否在多边形内部
  const index = polygonVertices.findIndex((item, i) => {
    const path = pathList[i];
    return isInside(ctx, path, { x: mouseX, y: mouseY });
  });
  console.log(index);
  if (index > -1) {
    ctx2.reset();
    render(ctx2, polygonVertices[index], "rgba(0,254,233,1)");
    showToolTip({
      x: mouseX,
      y: mouseY,
      ctx: ctx2,
      properties: txts[index],
      width: 200,
      height: 80,
    });
    i = index;
  } else {
    ctx2.reset();
    i = -1;
  }
});

c2.addEventListener("click", function () {
  if (i > -1) {
    const a = document.createElement("a");
    a.href = "https://www.baidu.com/s?wd=" + txts[i].name + "文旅";
    a.target = "_blank";
    a.click();
    a.remove();
  }
});
